﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter__GoodSalesManager : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindPro();
        }

        if (_User.isActivation == false)
        {
            hIsActivation.Value = "0";  //记录在控件中            
        }
        hBalance.Value = _User.VirtualMoney.ToString();
        hBV.Value = _User.BV.ToString();

        //查询会员返还货币余额
        lbVirtual.Text = "   <font color='red'>" + _User.VirtualMoney.ToString() + "</font>";
        lbBv.Text = "   <font color='red'>" + _User.BV.ToString() + "</font>"; 
    }

    #region 窗体设计器生成的代码

    protected override void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        //ThirdLevelPassword = true;     // 二级验证

        RequestLoginPage = "BalanceCenter/_GoodSalesManager.aspx";

        base.OnInit(e);
    }

    #endregion

    protected void BindPro()
    {
        DataTable dt = new DataTable();

        string TypeNorm = "";
        switch (_User.UserType)
        {
            case 1:
                TypeNorm = "A";
                break;
            case 2:
                TypeNorm = "B";
                break;
            case 3:
                TypeNorm = "C";
                break;
            case 4:
                TypeNorm = "D";
                break;
        }

        try
        {
            dt = DAL.Tables.T_GoodType.Select("", "", "");
        }
        catch { }

        //-----------------------分页代码-----------------------//
        PagedDataSource Pds = new PagedDataSource();
        Pds.DataSource = dt.DefaultView;

        Pds.AllowPaging = true; //开启分页
        Pds.PageSize = 6; //分页

        int index = int.Parse(PageIndex.Text); //当前页数
        int PageSize = Pds.PageSize;
        int TotalRecords = Pds.DataSourceCount;
        int TotalPages = TotalRecords / PageSize;//得到总页数（总记录数除以每页的记录数） 
        int ModePages = TotalRecords % PageSize;//得到取模的余数(总记录数取模每页的记录数) 

        if (ModePages > 0)//如果取模数不等于0，则把总页数加1 
        {
            TotalPages += 1;
        }
        if (TotalPages == 0)
        {
            TotalPages = 1;
        }
        this.ViewState["TotalPages"] = TotalPages;

        MaxPage.Text = TotalPages.ToString();//显示页面上的总页数 
        TotalCount.Text = TotalRecords.ToString();//显示页面上的总记录数 
        Pds.CurrentPageIndex = index - 1;

        //this.labTotalCount.Text = TotalRecords.ToString();
        //this.labPageCount.Text = Pds.PageSize.ToString();

        if (index == 1)
        {
            lnkHome.Enabled = false;
            lnkPrev.Enabled = false;
            if (TotalPages > 1)
            {
                lnkNext.Enabled = true;
                lnkEnd.Enabled = true;
            }
            else
            {
                lnkNext.Enabled = false;
                lnkEnd.Enabled = false;
            }
        }
        else
        {
            lnkHome.Enabled = true;
            lnkPrev.Enabled = true;
            if (index == TotalPages)
            {
                lnkNext.Enabled = false;
                lnkEnd.Enabled = false;
            }
            else
            {
                lnkNext.Enabled = true;
                lnkEnd.Enabled = true;
            }
        }

        selectPage.Items.Clear(); //清除防止累加
        for (int i = 1; i <= TotalPages; i++)
        {
            selectPage.Items.Add(i.ToString());
        }
        selectPage.Items.FindByText(index.ToString()).Selected = true; //把当前页显示在列表框的第一个

        this.dlInfo.DataSource = Pds;
        this.dlInfo.DataBind();
    }

    protected void lnkHome_Click(object sender, EventArgs e)
    {
        int index = 1;
        PageIndex.Text = index.ToString();
        BindPro();
    }

    protected void lnkPrev_Click(object sender, EventArgs e)
    {
        int index = int.Parse(PageIndex.Text);
        index--;
        PageIndex.Text = index.ToString();
        BindPro();
    }

    protected void lnkNext_Click(object sender, EventArgs e)
    {
        int index = int.Parse(PageIndex.Text);
        index++;
        PageIndex.Text = index.ToString();
        BindPro();
    }

    protected void lnkEnd_Click(object sender, EventArgs e)
    {
        int index = ShoveEL._Convert.StrToInt(this.ViewState["TotalPages"].ToString(), 0);
        PageIndex.Text = index.ToString();
        BindPro();
    }

    protected void ddlPage_SelectedIndexChanged(object sender, EventArgs e)
    {
        PageIndex.Text = selectPage.SelectedValue;
        BindPro();
    }
  
}
